<?php

namespace App\Http\Controllers\Api\Finance;

use App\Http\Controllers\Controller;
use App\Libs\Strategy\Context;
use App\Models\Orders\PayOrder;
use Illuminate\Http\Request;

class PayOrderController extends Controller
{
    private $finance;

    public function __construct()
    {
        $this->finance = new Context(new PayOrder());
    }

    public function index(Request $request)
    {
        $orders = $this->finance->display($request->limit,function($query) use($request){
            $query->with('member');
            if($request->keyword)
            {
                $query->whereHas('member',function($query){
                    $query->where('nickname','like','%'.request()->keyword.'%')->orWhere('mobile',request()->keyword);
                })->orWhere('order_sn','like','%'.$request->keyword.'%');
            }
            if($request->status)
            {
               $query->where('status',$request->status);
            }
            if($request->payment)
            {
               $query->where('payment',$request->payment);
            }
            if(isset($request->time[0]) && !empty($request->time[0])){
                $query->whereBetween('created_at',$request->time);
            }
            return $query;
        });
        return $this->success($orders);
    }

}
